package com.lixw.saa.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.function.Consumer;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

/**
 * @ClassName: ChatMemoryh4RedisController
 * @Description:
 * @Author: xuweiLi
 * @Create: 2025/10/3 16:10
 **/
@RestController
public class ChatMemory4RedisController {
    @Resource(name = "qwenChatClient")
    private ChatClient qwenChatClient;

    @GetMapping("/chatmemory/chat")
    public String chat(@RequestParam("msg") String msg,@RequestParam("userId") String userId) {
        return qwenChatClient.prompt(msg)
                .advisors(new Consumer<ChatClient.AdvisorSpec>() {
                    @Override
                    public void accept(ChatClient.AdvisorSpec advisorSpec) {
                        advisorSpec.param(CONVERSATION_ID, userId);
                    }
                })
                .call()
                .content();
    }
}